home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWArchiv / Include / FWObjReg.h < prev   
Encoding:
C/C++ Source or Header  |  1994-04-21  |  2.8 KB  |  97 lines  |  [TEXT/MPS ]

  1. #ifndef FWOBJREG_H
  2. #define FWOBJREG_H
  3. //========================================================================================
  4. //
  5. //    File:                FWObjReg.h
  6. //    Release Version:    $ 1.0d1 $
  7. //
  8. //    Creation Date:        3/28/94
  9. //
  10. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //========================================================================================
  13.  
  14. //========================================================================================
  15. // CLASS FW_CObjectRegistry
  16. //========================================================================================
  17.  
  18. class FW_CObjectRegistry
  19. {
  20. public:
  21.  
  22.     FW_CObjectRegistry();
  23.     virtual ~FW_CObjectRegistry();
  24.     
  25.     typedef long ID;
  26.     
  27.     enum {kNotInRegistry = -1};
  28.     
  29.     virtual FW_CObjectRegistry::ID Register(const void *object) = 0;
  30.         // Register an object and returns the (unique) ID
  31.     
  32.     virtual void Register(const void *object, FW_CObjectRegistry::ID id) = 0;
  33.         // Register an object to particular id.
  34.         // The id must not already be in the registry.
  35.     
  36.     virtual FW_CObjectRegistry::ID Lookup(const void *object) = 0;
  37.         // Look up an object in the registry, return kNonInRegistry if object not found.
  38.  
  39.     virtual const void* Lookup(FW_CObjectRegistry::ID id) = 0;
  40.         // Find an object by ID, return its pointer.
  41.         // Return 0 if id not in registry.
  42. };
  43.  
  44. //========================================================================================
  45. // CLASS FW_CBasicObjectRegistry
  46. //========================================================================================
  47.  
  48. class FW_CBasicObjectRegistry : public FW_CObjectRegistry
  49. {
  50. public:
  51.  
  52.     FW_CBasicObjectRegistry();
  53.     virtual ~FW_CBasicObjectRegistry();
  54.     
  55.     virtual FW_CObjectRegistry::ID Register(const void *object);
  56.         // Register an object and return its ID.
  57.     
  58.     virtual void Register(const void *object, FW_CObjectRegistry::ID id);
  59.         // Register an object to particular id
  60.     
  61.     virtual FW_CObjectRegistry::ID Lookup(const void *object);
  62.         // Look up an object in the registry, return kNonInRegistry if object not found.
  63.  
  64.     virtual const void* Lookup(FW_CObjectRegistry::ID id);
  65.         // Find an object by ID, return its pointer.
  66.         // Return 0 if id not in registry.
  67.  
  68. private:
  69.  
  70.     void GrowList();
  71.         // Grow the list by kExpansion slots
  72.     
  73.     struct SAssociation
  74.     {
  75.         FW_CObjectRegistry::ID    fID;            // object id
  76.         const void*                fObject;        // object address
  77.     };
  78.  
  79.     void InitAssociation(SAssociation& assoc)
  80.     {
  81.         assoc.fID = kNotInRegistry;
  82.         assoc.fObject = 0;
  83.     }
  84.  
  85.     enum {kExpansion = 8};
  86.     SAssociation*             fList;
  87.     long                    fListLength;
  88.     long                    fPhysicalListLength;
  89.     FW_CObjectRegistry::ID    fNextUnusedID;
  90.  
  91.     FW_CBasicObjectRegistry(const FW_CBasicObjectRegistry& readableArchive);
  92.     FW_CBasicObjectRegistry& operator=(const FW_CBasicObjectRegistry& registry);
  93.         // Copy constructor and assignment operator not valid for this class.
  94. };
  95.  
  96. #endif
  97.